import React, { Component } from 'react';
class Ueditor extends Component {
  constructor(props) {
    super(props);
  }

  state={
    id:this.props.id?this.props.id:null,
    ueditor:null,
    value:''
  }

  componentDidMount(){
    let UE = window.UE;
    let {id} = this.state;
    let that = this
    if(id){
      try {
        /*加载之前先执行删除操作，否则如果存在页面切换，
        再切回带编辑器页面重新加载时不刷新无法渲染出编辑器*/
        UE.delEditor(id);
      }catch (e) {}
      let ueditor = UE.getEditor(id, {
        autoHeightEnabled: false,
        autoFloatEnabled: true
      });
      this.setState({ueditor});
      ueditor.addListener('selectionchange',function(type, arg1, arg2){   //addListener监听事件，selectionchange输入框改变事件
        that.setState({
          value:ueditor.getContent()
        })
      })
    }
  }

  render() { 
    let {id} = this.state;
    return ( <div id={id}></div> );
  }
}
 
export default Ueditor;